package com.ebpm.designer.line
{
	import com.ebpm.designer.WF;
	import com.ebpm.designer.WP;
	import com.ebpm.designer.WorkPanel;
	import com.ebpm.designer.dir.LineEndDir;
	import com.ebpm.designer.dir.LineFromDir;
	
	public class RDLine extends Line
	{
		public function RDLine()
		{
			this.resizeFromDir = new LineFromDir(this, "upDownIcon");
			this.resizeToDir = new LineEndDir(this, "leftRightIcon");
			this.lineHeadType = "up";
			super();
		}
		
		override protected function initPoints(fromX:Number, fromY:Number, x:Number, y:Number):void {
			var itemSize:Number = WF.ITEM_SIZE;
			var p1:Point = new Point(x + (itemSize / 2) + this.resizeToExtraX, fromY + (itemSize / 2) + this.resizeFromExtraY);
			this.points.addItem(p1);
		}
		
		override public function repaintLine(type:String = "to"):void {
			var fromX:Number = this.sourceItem.nodeContainer.getRightLineX();
			var fromY:Number = this.sourceItem.nodeContainer.getRightLineY();
			var toX:Number = this.targetItem.nodeContainer.getDownLineX();
			var toY:Number = this.targetItem.nodeContainer.getDownLineY();
			if(this.startPoint.y - this.endPoint.y <= WF.LINE_HEAD_W) {
				WF.wp.removeElement(this);
				this.sourceItem.sourceLines.removeItem(this);
				this.targetItem.targetLines.removeItem(this);
				var line:Line = new RLLine().paint(fromX, fromY, this.targetItem.nodeContainer.getLeftLineX(), this.targetItem.nodeContainer.getLeftLineY());
				this.sourceItem.sourceLines.addItem(line);
				line.sourceItem = this.sourceItem;
				this.targetItem.nodeContainer.leftItem.targetLines.addItem(line);
				line.targetItem = this.targetItem.nodeContainer.leftItem;
			}
			else if((this.points.getItemAt(1) as Point).x <= this.startPoint.x) {
				WF.wp.removeElement(this);
				this.sourceItem.sourceLines.removeItem(this);
				this.targetItem.targetLines.removeItem(this);
				var line:Line = new RRLine().paint(fromX, fromY, this.targetItem.nodeContainer.getRightLineX(), this.targetItem.nodeContainer.getRightLineY());
				this.sourceItem.sourceLines.addItem(line);
				this.targetItem.nodeContainer.rightItem.targetLines.addItem(line);
				line.sourceItem = this.sourceItem;
				line.targetItem = this.targetItem.nodeContainer.rightItem;
			}
			else {
				this.points.removeAll();
				this.startPoint = null;
				this.endPoint = null;
				paint(fromX, fromY, toX, toY);
				resizeContent();
			}
		}
		
		public function resizeContent():void {
			txtInput.x = this.endPoint.x + 40;
			txtInput.y = this.endPoint.y - 26;
			txtLabel.x = this.txtInput.x;
			txtLabel.y = this.txtInput.y;
		}
		
		//拖拽框移动
		override public function resizeFromItem():void {
			if(this.isFirstMove) {
				this.resizeStartExtra = this.resizeFromExtraY;
				this.isFirstMove = false;
			}
			this.resizeFromExtraY = this.resizeStartExtra + WP.mouseChangeY;
			this.points.removeAll();
			var fromX = this.sourceItem.nodeContainer.getRightLineX();
			var fromY = this.sourceItem.nodeContainer.getRightLineY();
			var toX = this.targetItem.nodeContainer.getDownLineX();
			var toY = this.targetItem.nodeContainer.getDownLineY();
			this.paint(fromX, fromY, toX, toY);
		}
		
		
		override public function resizeEndItem():void {
			if(this.isFirstMove) {
				this.resizeStartExtra = this.resizeToExtraX;
				this.isFirstMove = false;
			}
			this.resizeToExtraX = this.resizeStartExtra + WP.mouseChangeX;
			this.points.removeAll();
			var fromX = this.sourceItem.nodeContainer.getRightLineX();
			var fromY = this.sourceItem.nodeContainer.getRightLineY();
			var toX = this.targetItem.nodeContainer.getDownLineX();
			var toY = this.targetItem.nodeContainer.getDownLineY();
			this.paint(fromX, fromY, toX, toY);
			this.movingTxtByLine();
		}
		
		
		
		
		
		
		
		
	}
}